package com.mew.chess.core.game.shbz.game.task;


import com.mew.chess.core.game.shbz.game.ShbzGameManager;
import com.mew.chess.core.game.shbz.game.ShbzTableManager;
import com.mew.chess.core.game.shbz.game.common.FishConstantValue;
import com.mew.chess.core.game.shbz.game.common.FishLinkType;
import com.mew.common.rest.bo.GameSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class FishScheduleTask {

    public boolean fishCycle(int roomId, int table){

        ShbzTableManager tableManager = ShbzGameManager.getInstance().getController(roomId).getTable(table);

        tableManager.getOnlineUserMap().forEach((k, v) -> {
            GameSession session = v.getGameSession();
            if (null == session || session.isWeakClose()){
                System.out.println("------------------------"+k);
                tableManager.clearOnlineUser(k);
            }
        });

        if (tableManager.getOnlineUserMap().isEmpty()){
            log.info("Fish roomId {} not real user is stop ", roomId);
            tableManager.stopGame();
            return false;
        }
        tableManager.fishClear();
        startGameLinkType(tableManager);

        return true;
    }

    public void startGameLinkType(ShbzTableManager tableManager){
        tableManager.setRuleTime(FishConstantValue.fishRedisValue.fish_timer_cycle);
        tableManager.setLinkType(FishLinkType.Fish.code());
        tableManager.setStartTime(System.currentTimeMillis());
    }



}
